<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
if(isset($_GET["field"])){
    if($_GET["field"]==""){
        echo "false";
        exit;
    }
    $id=intval($_GET["id"]);
    $field=trim($_GET["catdir"]);
    if($id>0){
        $row=$ezhand->select(MOD,'*','catdir="'.$field.'" and id<>"'.$id.'"');
    }else{
        $row=$ezhand->select(MOD,'*','catdir="'.$field.'"');
    
    }
    if(empty($row)){
        echo "true";
        exit;        
    }else{
        echo "false";
        exit;        
    }
    
}

if($_POST['sub']!=''){
    $id=empty($_POST['id'])?0:(int)$_POST['id'];
	unset($_POST['id']);
	unset($_POST['sub']);
	$data=array('modelid'=>trim($_POST['modelid']),'parentid'=>trim($_POST["parentid"]),'catname'=>trim($_POST["catname"]),
    'catdir'=>trim($_POST["catdir"]),
    'images'=>trim($_POST["images"]),
    'workflowid'=>trim($_POST["workflowid"]),
    'liststyle'=>intval($_POST["liststyle"]),
    'meta_title'=>strip_tags(trim($_POST["meta_title"])),
    'meta_keywords'=>strip_tags(trim($_POST["meta_keywords"])),
    'meta_description'=>strip_tags(trim($_POST["meta_description"])),
    
    );
    $data["level"]=0;
    if($_POST["parentid"]>0){
        $data["level"]=$ezhand->get_cat_level($_POST["parentid"]);
    }
    
    if(trim($_POST['catname'])==""){
        jumpajax('300','栏目名称不能为空!','');
    }
    if(trim($_POST['catdir'])==""){
        jumpajax('300','栏目英文目录名不能为空!','');
    }
    $catdir=trim($_POST["catdir"]);
 	if($id==0){
        $row=$ezhand->select(MOD,'*','catdir="'.$catdir.'"');
        if(!empty($row)){
            jumpajax('300','栏目英文目录名不能重复!','');
        }
        $id=$ezhand->insert(MOD,$data);

		jumpajax('200','保存成功','','closeCurrent');
	}
	else{
        $row=$ezhand->select(MOD,'*','catdir="'.$catdir.'" and id<>'.$id);
        if(!empty($row)){
            jumpajax('300','栏目英文目录名不能重复!','');
        }
	    $ezhand->update(MOD,$data,'id="'.$id.'"');
		jumpajax('200','修改成功','','closeCurrent');
	}
}
else{
	$id=empty($_GET['id'])?0:(int)$_GET['id'];
    
    $parentid=empty($_GET['parentid'])?0:(int)$_GET['parentid'];
    
    
    
    $catlist[0]="作为一级栏目";
    $catlisttemp=$ezhand->get_cattree(0);
   // print_r($catlist);
    //while(list($k,$v)=each($catlisttemp)){
    //   $catlist[$k]=$v["catname"];
                
   // }
   // print_r($catlisttemp);
    
    /*
    $catlist1=$ezhand->select_all(MOD,"id,catname,parentid,level"," 1=1 order by parentid asc,listorder asc");
    
    while(list($k,$v)=each($catlist1)){
        $f="";
        $catid=$v["id"];
        if($v["level"]==1){
            $f="&nbsp;";
        }elseif($v["level"]==2){
            $f="&nbsp;&nbsp;";
        }elseif($v["level"]==3){
            $f="&nbsp;&nbsp;&nbsp;";
        }elseif($v["level"]==4){
            $f="&nbsp;&nbsp;&nbsp;&nbsp;";

        }
        //&nbsp;├   └ 
        $catlist[$catid]=$f.$v["catname"];
    } 
    */   
    
    
    $rowlist=ez_get_cache("model");
    $modellist=array("0"=>"作为单页面");
    while(list($k,$v)=each($rowlist)){
        $modellist[$k]=$v["title"];
    }
     
    if($id==0){
	    $row=array();
        $row["parentid"]=$parentid;
	}else{
	   
	    $row=$ezhand->select(MOD,'*','id="'.$id.'"');
	}
}
?>